package nsoft.swing.action;

import java.awt.AWTEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class ApplicationEventListener<T extends AWTEvent> implements
		ActionListener, KeyListener, MouseListener, ItemListener {

	/**
	 * serialVersionUID = 1L.
	 */
	private static final long serialVersionUID = 1L;
	private ApplicationAction action;

	public ApplicationEventListener(String name, String method,
			Object controller) {
		this(name, method, controller, null);

	}

	public ApplicationEventListener(String name, String method,
			Object controller, String description) {
		this(new ApplicationAction(name, method, controller, description));
	}

	public ApplicationEventListener(ApplicationAction action) {
		this.action = action;
	}

	public void actionPerformed(ActionEvent e) {
		fireEvent((T) e);

	}

	public void keyPressed(KeyEvent e) {
		fireEvent((T) e);

	}

	public void keyReleased(KeyEvent e) {
		fireEvent((T) e);

	}

	public void keyTyped(KeyEvent e) {
		fireEvent((T) e);

	}

	public void mouseClicked(MouseEvent e) {
		fireEvent((T) e);

	}

	public void mouseEntered(MouseEvent e) {
		fireEvent((T) e);

	}

	public void mouseExited(MouseEvent e) {
		fireEvent((T) e);

	}

	public void mousePressed(MouseEvent e) {
		fireEvent((T) e);

	}

	public void mouseReleased(MouseEvent e) {
		fireEvent((T) e);

	}

	public void fireEvent() {
		fireEvent(null);
	}

	public void fireEvent(T event) {
		action.perforAWTAction(new ApplicationEvent<T>(event));
	}

	public void itemStateChanged(ItemEvent e) {
		fireEvent((T) e);

	}
}
